package com.zf.bm.common.validator;

import com.zf.bm.modules.policy.entity.PolicyKeywordFileValidate;
import com.zf.bm.modules.policy.model.RawContentPair;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.List;

public class MyConstraintValidate implements ConstraintValidator<ValidateParam, PolicyKeywordFileValidate> {

    @Override
    public void initialize(ValidateParam constraintAnnotation) {
        // nothing need to do
    }

    @Override
    public boolean isValid(PolicyKeywordFileValidate policyKeywordFile, ConstraintValidatorContext context) {
        if (policyKeywordFile.getRuleType()==1){
            return true;
        }
        String str = policyKeywordFile.getRuleContent();

        if (str.length() < 4) return false;

        List<RawContentPair> from = RawContentPair.from(str);
        return from.size() != 0;
    }
}
